<?php
namespace app\admin\controller;

use app\common\model\Recommend as RecommendModel;
use app\common\controller\AdminBase;
use think\Config;
use think\Db;

class Recommend extends AdminBase
{
    protected $recommend_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->recommend_model = new RecommendModel();
    }

    public function index($keyword = '', $page = 1)
    {
        $map = [];
        if ($keyword) {
            $map['referrer'] = ['like', "%{$keyword}%"];
        }
        $recommend_list = $this->recommend_model->where($map)->order('id DESC')->paginate(15, false, ['page' => $page]);

        return $this->fetch('index', ['recommend_list' => $recommend_list, 'keyword' => $keyword]);
    }

    public function delete($id = 0, $ids = [])
    {
        $id = $ids ? array_merge($ids) : $id;
        if ($id) {
            if ($this->recommend_model->destroy($id)) {
                $this->success('删除成功');
            } else {
                $this->error('删除失败');
            }
        } else {
            $this->error('请选择需要删除的内容');
        }
    }
}